import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

/**
 * Created by nanxin.cnx on 2015/8/6.
 */
public class HashSetTest {
    public static void main(String[] args) {
        HashSet<Integer> set1 = new HashSet();
        HashSet<Integer> set2 = new HashSet();
        List<Integer> list1 = new ArrayList<>();
        List<Integer> list2 = new ArrayList<>();

        for (int i = 0; i < 1000000; i++) {
            set1.add(i);
            list1.add(i);
        }for (int i = 0; i < 2000000; i++) {
            set2.add(i);
            list2.add(i);
        }
       long start,end;
        start = System.currentTimeMillis();
        for (int i : set1) {
            set2.contains(i);
        }
        end = System.currentTimeMillis();
        System.out.println("set: " + (end - start));

        start = System.currentTimeMillis();
        for (int i : list1) {
            list2.contains(i);
        }
        end = System.currentTimeMillis();
        System.out.println("list: " + (end - start));

    }
}
